package qc.module.sl.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import qc.module.sl.dto.project.classify.ProjectClassifyDto;
import qc.module.sl.dto.project.classify.ProjectClassifyQueryConditionDto;
import qc.module.sl.entity.SlBasicProjectClassify;
import qc.module.sl.mapper.BasicProjectClassifyMapper;
import qc.module.sl.repository.SlBasicProjectClassifyRepository;

import java.util.List;

/**
 * BasicProjectClassifyService
 *
 * @author QuCheng Tech
 * @create 2023/02/14
 */
@Service
public class BasicProjectClassifyService {
    private SlBasicProjectClassifyRepository repository;
    
    @Autowired
    public void setSlBasicProjectClassifyRepository(SlBasicProjectClassifyRepository repository){
        this.repository = repository;
    }
    
    /**
     * 查询水利工程分类信息，可用于返回启用状态的全部分类信息
     * 
     * @param	dto	
     * @return 水利工程分类信息集合
     * @author QcCheng Tech
     * @since 2023/2/15
     */
    public List<ProjectClassifyDto> query(ProjectClassifyQueryConditionDto dto){
        LambdaQueryWrapper<SlBasicProjectClassify> wrapper = new LambdaQueryWrapper<>();
        
        if (dto != null){
            if (!StringUtils.isBlank(dto.getStatus()) )
                if (dto.getStatus().equals("0") || dto.getStatus().equals("1"))
                    wrapper.eq(SlBasicProjectClassify::getEnable, dto.getStatus());
            if (!StringUtils.isBlank(dto.getWords()))
                wrapper.and(k -> k.like(SlBasicProjectClassify::getCode , dto.getWords()).or().like(SlBasicProjectClassify::getName , dto.getWords()).or().like(SlBasicProjectClassify::getDescription , dto.getWords()));
        }
        wrapper.orderByDesc(SlBasicProjectClassify::getName);
        
        List<SlBasicProjectClassify> list = repository.selectList(wrapper);
        
        if (list.size() > 0x0) 
            return BasicProjectClassifyMapper.MAPPER.toDtoList(list);
        
        return null;
    }
}
